package com.hsjk.szwj.module.official.controller.admin.video;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.official.controller.admin.video.vo.AdminOfficialWebsiteVideoCreateReqVO;
import com.hsjk.szwj.module.official.controller.admin.video.vo.AdminOfficialWebsiteVideoPageReqVO;
import com.hsjk.szwj.module.official.controller.admin.video.vo.AdminOfficialWebsiteVideoPageRespVO;
import com.hsjk.szwj.module.official.controller.admin.video.vo.AdminOfficialWebsiteVideoUpdateReqVO;
import com.hsjk.szwj.module.official.conver.video.OfficialWebsiteVideoConvert;
import com.hsjk.szwj.module.official.service.video.IOfficialWebsiteVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/07/31 22:29
 **/
@Tag(name = "官网后台 - 视频相关接口")
@RestController
@RequestMapping("/official-website/video")
@Validated
public class AdminOfficialWebsiteVideoController {

    @Resource
    private IOfficialWebsiteVideoService officialWebsiteVideoService;

    @PostMapping("/create")
    @Operation(summary = "创建视频")
    @PreAuthorize("@ss.hasPermission('official-website:video:create')")
    public CommonResult<Long> createOfficialWebsiteVideo(@Valid @RequestBody
                                                                 AdminOfficialWebsiteVideoCreateReqVO reqVO) {
        Long postId = officialWebsiteVideoService.createOfficialWebsiteVideo(reqVO);
        return success(postId);
    }

    @PutMapping("/update")
    @Operation(summary = "修改视频")
    @PreAuthorize("@ss.hasPermission('official-website:video:update')")
    public CommonResult<Boolean> updateOfficialWebsiteVideo(@Valid @RequestBody
                                                                    AdminOfficialWebsiteVideoUpdateReqVO reqVO) {
        officialWebsiteVideoService.updateOfficialWebsiteVideo(reqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除视频")
    @PreAuthorize("@ss.hasPermission('official-website:video:delete')")
    public CommonResult<Boolean> deleteOfficialWebsite(@RequestParam("id") Long id) {
        officialWebsiteVideoService.deleteOfficialWebsite(id);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得视频分页列表")
    @PreAuthorize("@ss.hasPermission('official-website:video:query')")
    public CommonResult<PageResult<AdminOfficialWebsiteVideoPageRespVO>> getOfficialWebsiteVideoPage(@Validated AdminOfficialWebsiteVideoPageReqVO reqVO) {
        return success(OfficialWebsiteVideoConvert.INSTANCE
                .convertAdminOfficialWebsiteVideoPageRespVO(officialWebsiteVideoService.getOfficialWebsiteVideoPage(reqVO)));
    }
}
